local extension = Package:new("SB")
extension.extensionName = "king"
local U = require "packages/utility/utility"


Fk:loadTranslationTable{
    ["SB"] = "傻逼",
  }
  
  local sb1 = General(extension, "sb1", "shu", 7)
  local sb__1 = fk.CreateTriggerSkill{
    name = "sb__1",
    anim_type = "offensive",
    events = {fk.CardUsing, fk.CardResponding},
    can_trigger = function(self, event, target, player, data)
      if target == player and player:hasSkill(self) and
        table.find(data.card.skillNames, function(name) return string.find(name, "longdan") end) then
        local id
        if event == fk.CardUsing then
          if data.card.trueName == "slash" then
            id = data.tos[1][1]
          elseif data.card.name == "jink" then
            if data.responseToEvent then
              id = data.responseToEvent.from  --jink
            end
          end
        elseif event == fk.CardResponding then
          if data.responseToEvent then
            if data.responseToEvent.from == player.id then
              id = data.responseToEvent.to  --duel used by zhaoyun
            else
              id = data.responseToEvent.from  --savsavage_assault, archery_attack, passive duel
            
              --TODO: Lenovo shu zhaoyun may chongzhen liubei when responding to jijiang
            end          
          end
        end 
        return  true
      end
    end,
    on_cost = function(self, event, target, player, data)
      local to = player.room:askForChoosePlayers(player, table.map(player.room:getOtherPlayers(player), Util.IdMapper), 1, 1,
      "#sb__1", self.name, true)
      if #to > 0 then
      self.cost_data = to[1]
      return true
      end
    end,
    on_use = function(self, event, target, player, data)
      local room = player.room
      room:notifySkillInvoked(player, self.name, "offensive")
      room:damage{
        from = player,
        to = room:getPlayerById(self.cost_data),
        damage = 1,
        skillName = self.name,
      }
      player:drawCards(1, self.name)  
    end,
  } 
  sb1:addSkill("longdan")
  sb1:addSkill(sb__1)
  Fk:loadTranslationTable{
   
    ["sb1"] = "傻逼1号",
    ["designer:sb1"] = "妄生",
    ["sb__1"] = "傻一",
    ["#sb__1"] = "你可以摸一张牌并对一名其他角色造成1点伤害",
    [":sb__1"] = "每当你发动〖龙胆〗使用或打出一张手牌时，你可以摸一张牌并对一名其他角色造成1点伤害",
  
  }
  
  


local sb2 = General(extension, "sb2", "qun", 4)
local function GetWuhuSkills(player)
  local mappers = Fk:currentRoom():getBanner("sb__2_wuhushangjiang")
  if mappers == nil then
    local skills = {}
    local generals = {}
    local SGmapper = {}
    for _, name in ipairs(player.room.general_pile) do
      if table.find({"guanyu", "zhangfei", "zhaoyun", "machao", "huangzhong"}, function(s)
          return name:endsWith(s)
        end) or name == "gundam" then  --高达！
        table.insert(generals, Fk.generals[name])
      end
    end
    if #generals == 0 then return {} end
    for _, general in ipairs(generals) do
      local list = general:getSkillNameList(true)
      for _, skill in ipairs(list) do
        table.insert(skills, skill)
        SGmapper[skill] = general.name
      end
    end
    mappers = {skills, SGmapper}
    Fk:currentRoom():setBanner("sb__2_wuhushangjiang", mappers)
  end
  return table.filter(mappers[1], function(s) return not player:hasSkill(s, true) end)
  end
local sb__2 = fk.CreateTriggerSkill {
  name = "sb__2",
  anim_type = "special",
  events = {fk.GameStart, fk.CardUseFinished, fk.CardRespondFinished, fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      if event == fk.GameStart then
        return true
      else
        if target == player then
          if event == fk.TurnEnd then
            return #player:getTableMark(self.name) > 0
          else
            return data.card.type == Card.TypeBasic and #player:getTableMark(self.name) < 99 and
              table.find(GetWuhuSkills(player), function(s)
                return string.find(Fk:getDescription(s, "zh_CN"), "【"..Fk:translate(data.card.trueName, "zh_CN").."】")
              end)
          end
        end
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.TurnEnd then
      local skills = player:getTableMark(self.name)
      local generals = table.map(skills, function(s) return player.room:getBanner("sb__2_wuhushangjiang")[2][s] end)
      local result = player.room:askForCustomDialog(player, self.name,
      "packages/utility/qml/ChooseSkillBox.qml", {
        skills, 0, 1, "#sb__2-invoke", generals,
      })
      if result == "" then return false end
      local choice = json.decode(result)
      if #choice > 0 then
        self.cost_data = choice[1]
        return true
      end
    else
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local mark = player:getTableMark(self.name)
    if event == fk.TurnEnd then
      table.removeOne(mark, self.cost_data)
      room:setPlayerMark(player, self.name, mark)
      room:handleAddLoseSkills(player, "-"..self.cost_data, nil, true, false)
    else
      local skills = {}
      local skill =  ""
      if event == fk.GameStart then
        skills = table.random(GetWuhuSkills(player), 20)
        if #skills == 0 then return end
        local generals = table.map(skills, function(s) return player.room:getBanner("sb__2_wuhushangjiang")[2][s] end)
        local result = room:askForCustomDialog(player, self.name,
        "packages/utility/qml/ChooseSkillBox.qml", {
          skills, 1, 10, "#sb__2-choose", generals,
        })        --选择技能结束
        if result == "" then
          skill = table.random(skills)     
          else
            skill = json.decode(result)

        end
      else
       skills = table.filter(GetWuhuSkills(player), function(s)
        return string.find(Fk:getDescription(s, "zh_CN"), "【"..Fk:translate(data.card.trueName, "zh_CN").."】")
      end)
       if #skills == 0 then return end
       skill = table.random(skills)
      end
      table.insertIfNeed(mark, skill)
      room:setPlayerMark(player, self.name, mark)
      room:handleAddLoseSkills(player, skill, nil, true, false)   --五虎]]
      --[[if #skills == 0 or result == "" then return end
        skill = json.decode(result)
         end
        table.insertIfNeed(mark, skill)
        room:handleAddLoseSkills(player, table.concat(skill, "|"), nil)]]

end
end,
}

sb2:addSkill(sb__2)
Fk:loadTranslationTable{
    ["sb2"] = "傻逼2号",
    ["designer:sb2"] = "妄生",
    ["sb__2"] = "傻二",
    [":sb__2"] = "游戏开始时，你从二十个五虎将技能中选择一个至十个获得。当你使用或打出一张基本牌后，"..
    "获得一个描述中包含此牌名的五虎将技能。回合结束时，你可以选择失去一个以此法获得的技能。",
    ["#sb__2-choose"] = "傻二：选择获得一个至十个五虎技能",
      ["#sb__2-invoke"] = "傻二：你可以失去一个五虎技能",
  }




  local sb3 = General(extension, "sb3", "shu", 14)
  local sb3Prohibit = fk.CreateProhibitSkill{
    name = "#sb__3_prohibit",
    prohibit_use = function(self, player, card)
      -- FIXME: 确保是因为【杀】而出闪，并且指明好事件id
      if Fk.currentResponsePattern ~= "jink" or card.name ~= "jink" or player:getMark("sb__3") == 0 then
        return false
      end
      if table.contains(player:getMark("sb__3"), card:getSuitString(true)) then
        return true
      end
    end,
  }
  local sb__3 = fk.CreateTriggerSkill{
    name = "sb__3",
    anim_type = "offensive",
    events = {fk.TargetSpecified},
    can_trigger = function(self, event, target, player, data)
      return target == player and player:hasSkill(self) and
        data.card.trueName == "slash" and
        #AimGroup:getAllTargets(data.tos) == 1 and
        player:getMark("@sb__3_Record") ~= 0
    end,
    on_use = function(self, event, target, player, data)
      local room = player.room
      local logic = room.logic
      local cardUseEvent = logic:getCurrentEvent().parent
      cardUseEvent.sb__3_used = true
  
      -- 让他不能出闪
      local to = room:getPlayerById(data.to)
      local suits = player:getMark("@sb__3_Record")
      room:setPlayerMark(to, self.name, suits)
  
      -- 展示牌堆顶的牌，计算加伤数量
      if #suits > 1 then
        local cards = room:getNCards(#suits + 10)
        room:moveCardTo(cards, Card.Processing, nil, fk.ReasonJustMove, self.name, nil, true, player.id)
        data.additionalDamage = data.additionalDamage or 0
        for _, id in ipairs(cards) do
          if table.contains(suits, Fk:getCardById(id):getSuitString(true)) then
            room:setCardEmotion(id, "judgegood")
            data.additionalDamage = data.additionalDamage + 100
          else
            room:setCardEmotion(id, "judgebad")
          end
          room:delay(200)
        end
        room:moveCardTo(cards, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, self.name)
      end
    end,
  
    refresh_events = {fk.TargetConfirmed, fk.CardUsing, fk.CardUseFinished},
    can_refresh = function(self, event, target, player, data)
      if not (target == player and player:hasSkill(self)) then return end
      local room = player.room
      if event == fk.CardUseFinished then
        return room.logic:getCurrentEvent().sb__3_used
      else
        return data.card.suit ~= Card.NoSuit
      end
    end,
    on_refresh = function(self, event, target, player, data)
      local room = player.room
      if event == fk.CardUseFinished then
        room:setPlayerMark(player, "@sb__3_Record", 0)
        for _, p in ipairs(room:getAlivePlayers()) do
          room:setPlayerMark(p, "sb__3", 0)
        end
      else
        local suit = data.card:getSuitString(true)
        local record = type(player:getMark("@sb__3_Record")) == "table" and player:getMark("@sb__3_Record") or {}
        table.insertIfNeed(record, suit)
        room:setPlayerMark(player, "@sb__3_Record", record)
      end
    end,
  }
  sb__3:addRelatedSkill(sb3Prohibit)
  sb3:addSkill(sb__3)
  Fk:loadTranslationTable{
    ["sb3"] = "傻逼3号",
    ["designer:sb3"] = "妄生",
    ["sb__3"] = "傻三",
    [":sb__3"] = "你使用牌时或成为其他角色使用牌的目标后，若此牌的花色未被此技能记录，"
     .. "则记录此种花色。当你使用【杀】指定唯一目标后，你可以亮出牌堆顶的X张牌"
     .. "（X为你记录的花色数+10，且至少为0），然后每有一张牌花色与此技能记录的"
     .. "花色相同，你令此【杀】伤害+100，且其不能使用此技能记录花色的牌响应此"
     .. "【杀】。若如此做，此【杀】结算结束后，清除此技能记录的花色。",
     ["@sb__3_Record"] = "傻三",
  }
  


  local sb4 = General(extension, "sb4", "wu", 4)
  local sb__4 = fk.CreateTriggerSkill{
    name = "sb__4",
    anim_type = "offensive",
    events = {fk.CardUseFinished},
    can_trigger = function(self, event, target, player, data)
      return target == player  and player:hasSkill(self)
    end,
    on_cost = function(self, event, target, player, data)
      return player.room:askForSkillInvoke(player, self.name, data, "#sb__lieji-invoke")
    end,
    on_use = function(self, event, target, player, data)
      local room = player.room
      for _, id in ipairs(player:getCardIds("h")) do
        local card = Fk:getCardById(id)
        if card.is_damage_card then
          room:addCardMark(card, "@sb__leiji_damage-inhand-turn")
        end
      end
    end,
    
    refresh_events = {fk.PreCardUse},
    can_refresh = function (self, event, target, player, data)
      return target == player and data.card:getMark("@sb__leiji_damage-inhand-turn") > 0
    end,
    on_refresh = function (self, event, target, player, data)
      data.additionalDamage = (data.additionalDamage or 0) + data.card:getMark("@sb__leiji_damage-inhand-turn")
    end,
}
local sb__4kurou = fk.CreateActiveSkill{
  name = "sb__4kurou",
  card_num = 1,
  target_num = 0,
  on_use = function(self, room, effect)
    local from = room:getPlayerById(effect.from)
    room:throwCard(effect.cards, self.name, from, from)
    room:loseHp(from, 1, self.name)
    if from:isAlive() then
      local player = room:getPlayerById(effect.from)
      while true do
        local judge = {
          who = player,
          reason = self.name,
        }
        room:judge(judge)
        if judge.card.trueName == "jink" or player.dead or not room:askForSkillInvoke(player, self.name) then
          break 
        end
      end
    end
  end
}
local sb__4kurou_obtain = fk.CreateTriggerSkill{
  name = "#sb__4kurou_obtain",
  mute = true,
  frequency = Skill.Compulsory,
  events = {fk.FinishJudge},
  can_trigger = function(self, event, target, player, data)
    return target == player and not player.dead and data.reason == "sb__4kurou" and data.card.trueName ~= "jink" and
    player.room:getCardArea(data.card) == Card.Processing
  end,
  on_use = function(self, event, target, player, data)
    player.room:obtainCard(player.id, data.card)
  end,
}
sb4:addSkill(sb__4kurou)
sb__4kurou:addRelatedSkill(sb__4kurou_obtain)
sb4:addSkill(sb__4)
Fk:loadTranslationTable{
  ["sb4"] = "傻逼4号",
  ["designer:sb4"] = "妄生",
  ["sb__4"] = "傻四其一",
  [":sb__4"] = "当你使用牌结算结束后，你可以令你当前手牌中的所有伤害牌的伤害基数+1直到回合结束。",
  ["#sb__lieji-invoke"] = "傻四：你可令当前手牌中的伤害牌伤害基数+1直到回合结束",
  ["@sb__leiji_damage-inhand-turn"] = "伤害+",
  ["sb__4kurou"] = "傻四其二",
  [":sb__4kurou"] = "你可弃置一张牌，然后失去一点体力，你可以亮出并获得牌堆顶的牌直到亮出的牌是【闪】为止。",
}


local sb5 = General(extension, "sb5", "god", 15)

local sb__5 = fk.CreateActiveSkill{
    name = "sb__5",
    anim_type = "offensive",
    target_num = 1,
    can_use = function(self, player)
      return player:hasSkill(self)
    end,
    card_filter = Util.FalseFunc,
    target_filter = function(self, to_select, selected, selected_cards)
      return Self.id ~= to_select
      end,
    on_use = function(self, room, effect)
      local player = room:getPlayerById(effect.from)
      local tos = room:getPlayerById(effect.tos[1])
      local choices = U.doStrategy(room, player, tos, {"data","xiuxi"}, {"fangyu","fanji"}, self.name, 1)
      if choices[1] == "data" and choices[2] ~= "fanji" then
        player:drawCards(1, self.name)
      elseif choices[1] == "data" and choices[2] ~=  "fangyu" then
        room:damage{
          from = player,
          to = tos,
          damage = 1,
          skillName = self.name,
        }
      elseif choices[1] == "xiuxi" and choices[2] ~= "fanji" then
        room:recover { num = 1, skillName = self.name, who = player , recoverBy = player}
      elseif choices[1] == "xiuxi" and choices[2] ~=  "fangyu" then
        room:damage{
          from = tos,
          to = player,
          damage = 1,
          skillName = self.name,
        }
      end
    end,
  }
  sb5:addSkill(sb__5)
Fk:loadTranslationTable{
  ["sb5"] = "傻逼5号",
  ["designer:sb5"] = "妄生",
  ["sb__5"] = "傻五",
  [":sb__5"] = "你可以与一名角色同时选择选项，若你博弈成功,且选项为打他，则对其造成一点伤害，若选项为休息，则恢复一点体力" ,
  ["data"] = "打他",
  ["xiuxi"] = "休息",
  ["fangyu"] = "防御",
  ["fanji"] = "反击",
  [":data"] = "博弈成功可对其造成一点伤害",
  [":xiuxi"] = "博弈成功可恢复一点体力",
  [":fangyu"] = "博弈成功则可防御他的一点伤害",
  [":fanji"] = "博弈成功则可对其造成一点伤害  ",
  ["sb__5__choice"]="对打"

}

local sb6 = General(extension, "sb6", "wei", 4)
local sb__6 = fk.CreateActiveSkill{
  name = "sb__6",
  anim_type = "offensive",
  target_num = 1,
  can_use = function(self, player)
    return player:hasSkill(self)
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected, selected_cards)
    return Self.id ~= to_select
    end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local tos = room:getPlayerById(effect.tos[1])
    local n = player.hp
    if n > 0 then
      room:damage{
        from = player,
        to = tos,
        damage = n,
        skillName = self.name,player
      }
    if tos:isAlive() then
    room:loseHp(player, 1, self.name)
    else
    room:changeMaxHp(player, 1)
    room:recover { num = 1, skillName = self.name, who = player , recoverBy = player}
    room:drawCards(player, 2, self.name)
    end
  end
end,
}
sb6:addSkill(sb__6)
Fk:loadTranslationTable{
  ["sb6"] = "傻逼6号",
  ["designer:sb6"] = "妄生",
  ["sb__6"] = "傻六",
  [":sb__6"] = "你可以对一名角色造成你的体力值点伤害,若对方死亡,则恢复一点体力并加一点体力上限,然后你摸两张牌，否则失去一点体力" ,

}

local sb7 = General(extension, "sb7", "jin", 4)
local sb__7 = fk.CreateActiveSkill{
  name = "sb__7",
  anim_type = "offensive",
  target_num = 1,
  can_use = function(self, player)
    return player:hasSkill(self)
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected, selected_cards)
    return Self.id ~= to_select
    end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local tos = room:getPlayerById(effect.tos[1])
    local judge = {
      who = room:getPlayerById(tos.id),
      reason = self.name,
      pattern = "peach,god_salvation|.",
    }
    room:judge(judge)
    if judge.card.name == "peach" and judge.card.name == "god_salvation" then
      room:killPlayer({who = player.id})
    else
      room:killPlayer({who = tos.id})
  end
end,
}
sb7:addSkill(sb__7)
Fk:loadTranslationTable{
  ["sb7"] = "傻逼7号",
  ["designer:sb7"] = "妄生",
  ["sb__7"] = "傻七",
  [":sb__7"] = "你可以让一名角色判定,若不为【桃】或【桃园结义】，其死亡,否则你死亡" ,
}


local sb8 = General:new(extension, "sb8", "wu", 4)
local sb__8 = fk.CreateTriggerSkill{
  name = "sb__8",
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  events = {fk.CardUsing, fk.CardResponding},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and
      not table.every({ 1, 2, 3 }, function(num)
        return player:getMark("@" .. self.name) % num ~= 0
      end)
  end,
  on_use = function(self, event, player, target, data)
    local loopList = table.filter({ 1, 2, 3 }, function(num)
      return player:getMark("@" .. self.name) % num == 0
    end)

    local toObtain = {}
    for _, count in ipairs(loopList) do
      local cardList = "slash,jink"
      if count == 2 then
        cardList = "peach,analeptic"
      elseif count == 3 then
        cardList = "ex_nihilo,duel"
      end
      local randomCard = player.room:getCardsFromPileByRule(cardList)
      if #randomCard > 0 then
        table.insert(toObtain, randomCard[1])
      end
    end

    if #toObtain > 0 then
      player.room:moveCards({
        ids = toObtain,
        to = player.id,
        toArea = Card.PlayerHand,
        moveReason = fk.ReasonPrey,
        proposer = player.id,
        skillName = self.name,
      })
    end
  end,

  refresh_events = {fk.CardUsing, fk.CardResponding, fk.EventLoseSkill},
  can_refresh = function(self, event, target, player, data)
    if event == fk.EventLoseSkill then
      return target == player and data == self
    end
    return player:hasSkill(self) and target == player
  end,
  on_refresh = function(self, event, target, player, data)
    if event == fk.EventLoseSkill then
      player.room:setPlayerMark(player, "@" .. self.name, 0)
    else
      player.room:addPlayerMark(player, "@" .. self.name, 1)
    end
  end,
}
sb8:addSkill(sb__8)
Fk:loadTranslationTable{
  ["sb8"] = "傻逼8号",
  ["sb__8"] = "傻8",
  [":sb__8"] = "锁定技，你每使用或打出：一张牌时，你随机获得一张【杀】或【闪】；两张牌时，你随机获得一张【桃】或【酒】；"..
  "三张牌时，你随机获得一张【无中生有】或【决斗】。",
  ["@sb__8"] = "傻8",
}



local sb9 = General(extension, "sb9", "qun", 3)
local sb__9_1 = fk.CreateTriggerSkill{
  name = "sb__9_1",
  anim_type = "offensive",
  events = {fk.CardUsing, fk.CardResponding},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target == player 
  end,
  on_cost = function(self, event, target, player, data)
    local to = player.room:askForChoosePlayers(player, table.map(player.room:getOtherPlayers(player), function (p)
      return p.id end), 1, 1, "#leiji-choose", self.name, true)
    if #to > 0 then
      self.cost_data = to[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local tar = room:getPlayerById(self.cost_data)
    local judge = {
      who = tar,
      reason = self.name,
      pattern = ".|.|spade",
    }
    room:judge(judge)
    if judge.card.suit == Card.Spade then
      room:damage{
        from = player,
        to = tar,
        damage = 2,
        damageType = fk.ThunderDamage,
        skillName = self.name,
      }
    end
end,
}
local sb__9_2 = fk.CreateTriggerSkill{
  name = "sb__9_2",
  anim_type = "control",
  events = {fk.AskForRetrial},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and not player:isNude()
  end,
  on_cost = function(self, event, target, player, data)
    local card = player.room:askForResponse(player, self.name, ".|.|spade,club|hand,equip", "#guidao-ask::" .. target.id .. ":" .. data.reason, true)
    if card ~= nil then
      self.cost_data = card
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    player.room:retrial(self.cost_data, player, data, self.name, true)
    player:drawCards(1, self.name)
  end,
}
sb9:addSkill(sb__9_1)
sb9:addSkill(sb__9_2)
Fk:loadTranslationTable{
  ["sb9"] = "傻逼9号",
  ["sb__9_1"] = "傻9其一",
  [":sb__9_1"] = "当你使用或打出牌时，你可以令一名角色进行判定，若结果为♠，你对其造成2点雷电伤害。",
  ["sb__9_2"] = "傻9其二",
  [":sb__9_2"] = "当一名角色的判定牌生效前，你可以打出一张黑色牌替换之，并摸一张牌。",
}


local sb10 = General(extension, "sb10", "god", 1)
-- gundam.hidden = true
local sb__10_1 = fk.CreateTriggerSkill{
  name = "sb__10_1",
  events = {fk.AfterCardsMove, fk.EventPhaseChanging},
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  mute = true,
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) then return false end
    if event == fk.EventPhaseChanging then
      return target == player and data.to == Player.Draw
    elseif player:getHandcardNum() ~= 10 then
      for _, move in ipairs(data) do
        if move.to == player.id and move.toArea == Card.PlayerHand then
          return true
        elseif move.from == player.id then
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Card.PlayerHand then
              return true
            end
          end
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke(self.name)
    if event == fk.EventPhaseChanging then
      room:notifySkillInvoked(player, self.name, "negative")
      return true
    else
      local num = 10 - player:getHandcardNum()
      if num > 0 then
        room:notifySkillInvoked(player, self.name, "drawcard")
        player:drawCards(num, self.name)
      elseif num < 0 then
        room:notifySkillInvoked(player, self.name, "negative")
        room:askForDiscard(player, -num, -num, false, self.name, false)
      end
    end
  end,
}
local sb__10_2 = fk.CreateViewAsSkill{
  name = "sb__10_2",
  mute = true,
  pattern = "peach,slash,jink,nullification",
  card_filter = function(self, to_select, selected)
    if #selected == 1 then
      return false
    else
      local suit = Fk:getCardById(to_select).suit
      local c
      if suit == Card.Heart then
        c = Fk:cloneCard("peach")
      elseif suit == Card.Diamond then
        c = Fk:cloneCard("fire__slash")
      elseif suit == Card.Club then
        c = Fk:cloneCard("jink")
      elseif suit == Card.Spade then
        c = Fk:cloneCard("nullification")
      else
        return false
      end
      return (Fk.currentResponsePattern == nil and c.skill:canUse(Self, c)) or
        (Fk.currentResponsePattern and Exppattern:Parse(Fk.currentResponsePattern):match(c))
    end
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then
      return nil
    end
    local suit = Fk:getCardById(cards[1]).suit
    local c
    if suit == Card.Heart then
      c = Fk:cloneCard("peach")
    elseif suit == Card.Diamond then
      c = Fk:cloneCard("fire__slash")
    elseif suit == Card.Club then
      c = Fk:cloneCard("jink")
    elseif suit == Card.Spade then
      c = Fk:cloneCard("nullification")
    else
      return nil
    end
    c.skillName = self.name
    c:addSubcards(cards)
    return c
  end,
}
local sb__10_2_qinggang = fk.CreateTriggerSkill{
  name = "#sb__10_2_qinggang",
  events = {fk.EventPhaseStart},
  mute = true,
  can_trigger = function(self, event, target, player, data)
    if target ~= player or not player:hasSkill(sb__10_2) or player.phase ~= Player.Start then return false end
    for _, id in ipairs(Fk:getAllCardIds()) do
      if Fk:getCardById(id).name == "qinggang_sword" and table.contains({Card.PlayerEquip, Card.PlayerJudge}, player.room:getCardArea(id)) then
        return true
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local cids, target = {}, nil
    for _, id in ipairs(Fk:getAllCardIds()) do
      if Fk:getCardById(id).name == "qinggang_sword" and table.contains({Card.PlayerEquip, Card.PlayerJudge}, room:getCardArea(id)) then
        table.insert(cids, id)
        target = target or room:getCardOwner(id).id
      end
    end
    if #cids == 0 then
      return false
    else
      local prompt = #cids == 1 and "#sb__10_2_qinggang-target:" .. target or "#sb__10_2_qinggang-targets:" .. target
      if room:askForSkillInvoke(player, self.name, data, prompt) then
        self.cost_data = cids
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:notifySkillInvoked(player, sb__10_2.name, "control")
    player:broadcastSkillInvoke(sb__10_2.name)
    table.forEach(self.cost_data, function(id)
      room:obtainCard(player, id, true, fk.ReasonPrey)
    end)
  end,

  refresh_events = {fk.AfterCardUseDeclared, fk.PreCardRespond},
  can_refresh = function(self, event, target, player, data)
    return target == player and table.contains(data.card.skillNames, "sb__10_2")
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    if data.card.trueName == "nullification" then
      player:broadcastSkillInvoke("sb__10_2", 1)
      room:notifySkillInvoked(player, "sb__10_2", "control")
    elseif data.card.trueName == "jink" then
      player:broadcastSkillInvoke("sb__10_2", 2)
      room:notifySkillInvoked(player, "sb__10_2", "defensive")
    elseif data.card.trueName == "peach" then
      player:broadcastSkillInvoke("sb__10_2", 3)
      room:notifySkillInvoked(player, "sb__10_2", "support")
    elseif data.card.trueName == "slash" then
      player:broadcastSkillInvoke("sb__10_2", 4)
      room:notifySkillInvoked(player, "sb__10_2", "offensive")
    end
  end,
}
sb__10_2:addRelatedSkill(sb__10_2_qinggang)
sb10:addSkill(sb__10_1)
sb10:addSkill(sb__10_2)
Fk:loadTranslationTable{
  ["sb10"] = "傻逼10号",
  ["sb__10_1"] = "傻10其一",
  [":sb__10_1"] = "锁定技，你跳过摸牌阶段；当你的手牌数大于10/小于10时，你将手牌弃置至10/摸至10张。",
  ["sb__10_2"] = "傻10其二",
  [":sb__10_2"] = "你可以将你的牌按以下规则使用或打出：红桃当【桃】，方块当火【杀】，梅花当【闪】，黑桃当【无懈可击】。准备阶段开始时，如果场上有【青釭剑】，你可以获得之。",

  ["#sb__10_2_qinggang"] = "傻10其二",
  ["#sb__10_2_qinggang-target"] = "傻10其二：你可夺走 %src 的【青釭剑】！",
  ["#sb__10_2_qinggang-targets"] = "傻10其二：你可夺走 %src 等的【青釭剑】！",

}


local sb11 = General(extension, "sb11", "wu", 4)
local sb__11 = fk.CreateProhibitSkill{
  name = "sb__11",
  frequency = Skill.Compulsory,
  is_prohibited = function(self, from, player, card)
    if player:hasSkill(self) then
      return card.trueName == "indulgence" or card.trueName == "snatch" or card.trueName == "slash" or card.trueName == "savage_assault" or card.trueName == "archery_attack" or card.trueName == "duel" or card.trueName == "dismantlement" or card.trueName == "collateral" or card.trueName == "fire_attack" or card.trueName == "iron_chain" or card.trueName == "supply_shortage" 
    end
  end,
}
sb11:addSkill(sb__11)
Fk:loadTranslationTable{
    ["sb11"] = "傻逼11号",
    ["designer:sb11"] = "妄生",
    ["sb__11"] = "傻11",
    [":sb__11"] = "你不能成为杀或普通锦囊牌的目标(除“五谷丰登”)" ,
}

local sb12 = General(extension, "sb12", "god", 3)
local sb__12 = fk.CreateTriggerSkill{
  name = "sb__12",
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  events = {fk.SkillEffect},
  can_trigger = function(self, _, target, player, data)
    return player:hasSkill(self) and data.visible and data ~= self and target and target:hasSkill(data, true, true) and
      data:isPlayerSkill(target) and not table.contains({ "m_feiyang", "m_bahu" ,"sb__12","jingyu"}, data.name) and
      player.room.logic:getCurrentEvent():findParent(GameEvent.Round, true) ~= nil
  end,
  on_use = function(self, _, target, player, data)
    local room = player.room
    player:drawCards(1, self.name)
  end,
}
Fk:loadTranslationTable{
  ["sb12"] = "傻逼12号",
  ["designer:sb12"] = "妄生",
  ["sb__12"] = "傻12",
  [":sb__12"] = "锁定技，当一名角色发动除“静域”、“傻12”外的技能时，你摸一张牌。" ,
}

sb12:addSkill(sb__12)


local sb13 = General(extension, "sb13", "wei", 3)
local sb__13 = fk.CreateTriggerSkill{
  name = "sb__13",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target.phase == Player.Finish 
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local to = room:askForChoosePlayers(player, table.map(player.room.alive_players, Util.IdMapper), 1, 1, "#sb__13-choose", self.name, true)
    if #to > 0 then
      self.cost_data = {tos = to}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data.tos[1])
    player.room:askForDiscard(player, 1, 1, false, self.name, false, nil, "#sb__13-choose", false)
    to:gainAnExtraTurn()
  end
}
sb13:addSkill(sb__13)
Fk:loadTranslationTable{
  ["sb13"] = "傻逼13号",
  ["designer:sb13"] = "妄生",
  ["sb__13"] = "傻13",
  [":sb__13"] = "一名角色的回合结束时，你可弃置一张手牌并选择一名角色，其获得一个额外的回合。" ,
  ["#sb__13-choose"] = "傻13：你可弃置一张手牌并选择一名角色，其获得一个额外的回合",
}

local sb14 = General(extension, "sb14", "qun", 3)
local sb__14 = fk.CreateTriggerSkill{
  name = "sb__14",
  anim_type = "drawcard",
  events = {fk.TargetConfirmed},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) 
  end,
  on_use = function(self, event, target, player, data)
    local n = player:usedSkillTimes(self.name)
    player:drawCards(n, self.name)
  end,
}
sb14:addSkill(sb__14)
Fk:loadTranslationTable{
    ["sb14"] = "傻逼14号",
    ["designer:sb14"] = "妄生",
    ["sb__14"] = "傻14",
    [":sb__14"] = "当你每回合成为牌的目标后，你可以摸1张牌，然后下次以此法摸牌数+1。每回合开始时，重置为1" ,
}

local sb15 = General(extension, "sb15", "qun", 4, 6)
local sb__15 = fk.CreateTriggerSkill{
  name = "sb__15",
  anim_type = "offensive",
  events = {fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) then
      return true
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local targets = {}
      for _, p in ipairs(room.alive_players) do
        if p ~= player and not p:isNude() then
          table.insert(targets, p.id)
        end
      end
      local to = room:askForChoosePlayers(player, targets, 1, 1, "#sb__15-choose", self.name, true)
      if #to > 0 then
        self.cost_data = {tos = to}
        return true
      end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local n = player:usedSkillTimes(self.name)
    room:damage({
      from = player,
      to = room:getPlayerById(self.cost_data.tos[1]),
      damage = math.random(0, n),
      skillName = self.name,
    })
  end,
}
sb15:addSkill(sb__15)
Fk:loadTranslationTable{
  ["sb15"] = "傻逼15号",

  ["sb__15"] = "傻15",
  [":sb__15"] = "你使用牌时，可以对一名其他角色随机造成0~n点伤害（n为你本回合累计使用牌的数量）。",
  ["#sb__15-choose"] = "狼袭：请选择一名其他角色，对其随机造成伤害",

}

local sb16 = General(extension, "sb16", "wu", 4)
local sb__16 = fk.CreateTriggerSkill{
  name = "sb__16",
  anim_type = "drawcard",
  derived_piles = "#sb16",
  events = {fk.GameStart, fk.TurnStart, fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      if event == fk.GameStart or event ==fk.TurnStart then
        return #player:getPile("#sb16") == 0
      elseif event == fk.CardUseFinished and #player:getPile("#sb16") > 0 and target == player then
        local c = Fk:getCardById(U.getPrivateMark(player, "$sb16")[1])
        if c.number == data.card.number or c:compareSuitWith(data.card) or c.trueName == data.card.trueName then
          return true
        else
          return player.room:getCardArea(data.card) == Card.Processing and #player:getPile("#sb16") < 13
        end
      elseif event == fk.CardUseFinished and #player:getPile("#sb16") == 0 and target == player then
        return true
      end
    end
  end,
  on_cost = function (self, event, target, player, data)
    if event == fk.GameStart or event ==fk.TurnStart then
      local choice = player.room:askForChoice(player, {"1", "2", "3", "4", "5"}, self.name, "#sb16-invoke")
      if choice ~= "Cancel" then
        self.cost_data = {choice = tonumber(choice)}
        return true
      end
    elseif event == fk.CardUseFinished then
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    if event == fk.GameStart or event ==fk.TurnStart then
      local result = room:askForGuanxing(player, room:getNCards(self.cost_data.choice), nil, {0, 0}, self.name, true, {"#sb16", ""})
      player:addToPile("#sb16", result.top, false, self.name, player.id)
      U.setPrivateMark(player, "$sb16", result.top)
    elseif event == fk.CardUseFinished and #player:getPile("#sb16") ~= 0 then
      local c = Fk:getCardById(U.getPrivateMark(player, "$sb16")[1])
      if c.number == data.card.number or c:compareSuitWith(data.card) or c.trueName == data.card.trueName then
        room:moveCardTo(c, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, self.name, nil, true, player.id)
        if not player.dead then
          player:drawCards(2, self.name)
        end
        if #player:getPile("#sb16") == 0 then
          room:setPlayerMark(player, "@[private]$sb16", 0)
        else
          U.setPrivateMark(player, "$sb16", player:getPile("#sb16"))
        end
      else
        local cards = table.simpleClone(player:getPile("#sb16"))
        for i = 1, 13 - #cards, 1 do
          table.insert(cards, Card:getIdList(data.card)[i])
        end
        local result = room:askForGuanxing(player, cards, nil, {0, 0}, self.name, true, {"#sb16", ""})
        cards = table.filter(result.top, function (id)
          return not table.contains(player:getPile("#sb16"), id)
        end)
        player:addToPile("#sb16", cards, false, self.name, player.id)
        --player.special_cards["#zhengyue"] = result.top  --FIXME: 危险！！！
        U.setPrivateMark(player, "$sb16", result.top)
      end
    elseif event == fk.CardUseFinished and #player:getPile("#sb16") == 0 then
        local choice = player.room:askForChoice(player, {"1", "2", "3", "4", "5"}, self.name, "#sb16-invoke")
        if choice ~= "Cancel" then
          self.cost_data = {choice = tonumber(choice)}
        local result = room:askForGuanxing(player, room:getNCards(self.cost_data.choice), nil, {0, 0}, self.name, true, {"#sb16", ""})
        player:addToPile("#sb16", result.top, false, self.name, player.id)
        U.setPrivateMark(player, "$sb16", result.top)
      end
    end
  end,

  on_lose = function (self, player, is_death)
    local room = player.room
    room:setPlayerMark(player, "@[private]$sb16", 0)
    room:moveCardTo(player:getPile("#sb16"), Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, "", nil, true)
  end,
}
sb16:addSkill(sb__16)
Fk:loadTranslationTable{
    ["sb16"] = "傻逼16号",
    ["designer:sbx"] = "妄生",
    ["sb__16"] = "傻16",
    [":sb__16"] = "游戏开始或你的回合开始或当你弃置你的武将牌上最后一张“16”牌时，你可以将牌堆顶至多五张牌以任意顺序置于武将牌上。当你使用牌结算后，若与武将牌上第一张"..
    "“16”牌点数或花色或牌名相同，移去第一张“16”牌并摸两张牌；若皆不同，将此牌置于武将牌上并任意调整顺序（至多13张“16”牌）。",
    ["#sb16"] = "16",
    ["@[private]$sb16"] = "16",
    ["#sb16-invoke"] = "16：将牌堆顶至多五张牌置为“16”牌",
    
}
local sb17 = General(extension, "sb17", "wei", 5)
local sb__17 = fk.CreateTriggerSkill{
  name = "sb__17",
  events = {fk.GameStart},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    for _, p in ipairs(room:getOtherPlayers(player, true)) do
      local skills = Fk.generals[p.general]:getSkillNameList(true)
      if p.deputyGeneral ~= "" then
        table.insertTableIfNeed(skills, Fk.generals[p.deputyGeneral]:getSkillNameList(true))
      end
      if #skills > 0 then
        skills = table.map(skills, function(skillName) return "-" .. skillName end)
        room:handleAddLoseSkills(p, table.concat(skills, "|"), nil, true, false)
      end
    end
  end,
}
sb17:addSkill(sb__17)
Fk:loadTranslationTable{
  ["sb17"] = "傻逼17号",
  ["designer:sb17"] = "ﻬ零之魔力",
  ["sb__17"] = "傻17",
  [":sb__17"] = "游戏开始时，场上其他角色失去所有技能。",
}
local sb18 = General(extension, "sb18", "wei", 3)
local sb__18 = fk.CreateTriggerSkill{
  name = "sb__18",
  events = {fk.CardUseFinished},
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return 
      target == player and
      player:hasSkill(self) and
      (data.extra_data or {}).firstCardSuitUseFinished and
      type(player:getMark("@18")) == "table" and
      #player:getMark("@18") == 4
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local suitsNum = #player:getMark("@18")
    local targets = {}
    local prompt 
    if suitsNum == 4 then
      targets = room:getOtherPlayers(player, false)
      prompt = "#18-damage"
    end
    if #targets == 0 then return end
    targets = table.map(targets, Util.IdMapper)
    local to = room:askForChoosePlayers(player, targets, 1, 1, prompt, self.name, true)
    if #to > 0 then
      self.cost_data = to[1]
      return true
    end
    return false
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local suitsNum = #player:getMark("@18")
    local to = room:getPlayerById(self.cost_data)
    if suitsNum == 4 then
      player:drawCards(4, self.name)
      room:damage({
        from = player,
        to = to,
        damage = 1,
        damageType = fk.NormalDamage,
        skillName = self.name,
      })
      room:setPlayerMark(player, "@18", 0)
    end
  end,

  refresh_events = {fk.CardUseFinished},
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(self, true) and target == player and
      data.card.suit ~= Card.NoSuit and
      (type(player:getMark("@18")) ~= "table" or
      not table.contains(player:getMark("@18"), "log_" .. data.card:getSuitString()))
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local typesRecorded = type(player:getMark("@18")) == "table" and player:getMark("@18") or {}
    table.insert(typesRecorded, "log_" .. data.card:getSuitString())
    room:setPlayerMark(player, "@18", typesRecorded)

    data.extra_data = data.extra_data or {}
    data.extra_data.firstCardSuitUseFinished = true
  end,

}
sb18:addSkill(sb__18)
Fk:loadTranslationTable{
  ["sb18"] = "傻逼18号",
  ["designer:sb18"] = "妄生",
  ["sb__18"] = "傻18",
  [":sb__18"] = "你使用牌后，若此牌的花色未被记录，则记录此种花色，每当你记录齐4种花色是，摸4张牌，然后清除记录的花色",
  ["#18-damage"] = "傻18:对一名角色造成一点伤害"
}
local sb19 = General(extension, "sb19", "jin", 4)
local sb__19 = fk.CreateTriggerSkill{
  name = "sb__19",
  anim_type = "control",
  events = {fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card.trueName ~= "slash" and data.card.type == Card.TypeBasic and
      table.find(player.room.alive_players, function (p)
        return not p:isKongcheng()
      end)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local targets = table.filter(room.alive_players, function (p)
      return not p:isKongcheng()
    end)
    local tos = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 4,
      "#sb__19-choose", self.name, true)
    if #tos > 0 then
      room:sortPlayersByAction(tos)
      self.cost_data = {tos = tos}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    for _, id in ipairs(self.cost_data.tos) do
      local p = room:getPlayerById(id)
      if not p.dead and not p:isKongcheng() then
        local card = room:askForCard(p, 1, 1, false, self.name, false, nil, "#sb__19-ask:"..player.id)
        room:moveCards({
          ids = card,
          from = id,
          toArea = Card.DrawPile,
          moveReason = fk.ReasonPut,
          skillName = self.name,
        })
      end
    end
    if player.dead then return end
    local use = U.askForUseVirtualCard(room, player, "enemy_at_the_gates", nil, self.name, "#sb__19-use", false)
    if use and not player.dead and  (use.extra_data and use.extra_data.sb__19_damageDealt) then
      player:drawCards(2, self.name)
    end
  end,

  refresh_events = {fk.Damage},
  can_refresh = function (self, event, target, player, data)
    return target == player and data.card and data.card.trueName == "slash" and
      table.contains(data.card.skillNames, "enemy_at_the_gates_skill")
  end,
  on_refresh = function (self, event, target, player, data)
    local e = player.room.logic:getCurrentEvent().parent
    while e do
      if e.event == GameEvent.UseCard then
        local use = e.data[1]
        if use.card.name == "enemy_at_the_gates" and table.contains(use.card.skillNames, "sb__19") then
          use.extra_data = use.extra_data or {}
          use.extra_data.sb__19_damageDealt = true
          return
        end
      end
      e = e.parent
    end
  end,
}
sb19:addSkill(sb__19)
Fk:loadTranslationTable{
  ["sb19"] = "傻逼19号",
  ["designer:sb19"] = "ﻬ零之魔力",
  ["sb__19"] = "傻19",
  [":sb__19"] = "当你使用一张非【杀】的基本牌时，你可以将至多四名角色依次将一张手牌置于牌堆顶，然后视为使用一张【兵临城下】，【兵临城下】结算之后，若造成伤害，则你摸2张牌",
  ["#sb__19-choose"] = "傻19：令至多四名角色依次将一张手牌置于牌堆顶，然后你视为使用一张【兵临城下】！",
  ["#sb__19-ask"] = "傻19：%src 将视为使用【兵临城下】！请将一张手牌置于牌堆顶",
  ["#sb__19-use"] = "傻19：视为使用一张【兵临城下】！若造成伤害，你摸两张牌",

}
local sb20 = General(extension, "sb20", "shu", 3)
local sb__20 = fk.CreateTriggerSkill{
  name = "sb__20",
  anim_type = "control",
  events ={fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
    return target ~= player and player:hasSkill(self) and player:usedSkillTimes(self.name) < 4
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    if room:askForSkillInvoke(player, self.name, nil,
    "#sb__20-invoke::"..target.id..":"..data.card:toLogString()) then
      room:doIndicate(player.id, {target.id})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    data.toCard = nil
    data.tos = {}
    player:drawCards(1, self.name)
  end,
}
sb20:addSkill(sb__20)
Fk:loadTranslationTable{
  ["sb__20"] = "傻20",
  ["designer:sb20"] = "ﻬ零之魔力",
  ["sb20"] = "傻逼20号",
  [":sb__20"] = "每回合限4次，当其他角色使用一张牌时，你可以令此牌无效并摸一张牌。",
  ["#sb__20-invoke"] = "傻20：是否令 %dest 使用的%arg无效？",
}








return extension





















